package com.sky.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@Slf4j
public class RedisConfiguration {

//    把Redis工厂对象交给Ioc管理
    @Bean
    public RedisTemplate redis(RedisConnectionFactory factory){
        log.info("RedisTemplate对象开始创建并初始...");
//        创建redis对象
        RedisTemplate redis = new RedisTemplate();
//        设置redis连接工厂对象
        redis.setConnectionFactory(factory);
//        设置redis的字符串key序列化
        redis.setKeySerializer(new StringRedisSerializer());
        return redis;
    }
}
